package gitlab_hook

import (
	"atomgit.com/openlinksaas-org/proto-gen-go.git/events/events_gitlab"
)

type JobHook struct {
	ObjectKind         string      `json:"object_kind"`
	Ref                string      `json:"ref"`
	Tag                bool        `json:"tag"`
	BeforeSha          string      `json:"before_sha"`
	Sha                string      `json:"sha"`
	BuildId            int64       `json:"build_id"`
	BuildName          string      `json:"build_name"`
	BuildStage         string      `json:"build_stage"`
	BuildStatus        string      `json:"build_status"`
	BuildStartedAt     customTime  `json:"build_started_at"`
	BuildFinishedAt    customTime  `json:"build_finished_at"`
	BuildDuration      float64     `json:"build_duration"`
	BuildAllowFailure  bool        `json:"build_allow_failure"`
	BuildFailureReason string      `json:"build_failure_reason"`
	PipelineId         int64       `json:"pipeline_id"`
	ProjectId          int64       `json:"project_id"`
	ProjectName        string      `json:"project_name"`
	User               User        `json:"user"`
	Commit             BuildCommit `json:"commit"`
	Repository         Repository  `json:"repository"`
	Runner             Runner      `json:"runner"`
}

func (item *JobHook) ToProtoBuf() *events_gitlab.JobEvent {
	return &events_gitlab.JobEvent{
		ObjectKind:         item.ObjectKind,
		Ref:                item.Ref,
		Tag:                item.Tag,
		BeforeSha:          item.BeforeSha,
		Sha:                item.Sha,
		BuildId:            item.BuildId,
		BuildName:          item.BuildName,
		BuildStage:         item.BuildStage,
		BuildStatus:        item.BuildStatus,
		BuildStartedAt:     item.BuildStartedAt.GetTimeStamp(),
		BuildFinishedAt:    item.BuildFinishedAt.GetTimeStamp(),
		BuildDuration:      float32(item.BuildDuration),
		BuildAllowFailure:  item.BuildAllowFailure,
		BuildFailureReason: item.BuildFailureReason,
		PipelineId:         item.PipelineId,
		ProjectId:          item.ProjectId,
		ProjectName:        item.ProjectName,
		User:               item.User.ToProtoBuf(),
		Commit:             item.Commit.ToProtoBuf(),
		Repository:         item.Repository.ToProtoBuf(),
		Runner:             item.Runner.ToProtoBuf(),
	}
}
